﻿@using XCode;
@using XCode.Configuration;
@{
    var pair = Model as Pair;
    var entity = pair.First as IEntity;
    var item = pair.Second as FieldItem;
}
@if (item.PrimaryKey)
{
    <td class="text-center hidden-md hidden-sm hidden-xs">@entity[item.Name]</td>
}
else
{
    switch (Type.GetTypeCode(item.Type))
    {
        case TypeCode.Boolean:
            if ((Boolean)entity[item.Name])
            {
                <td class="text-center">
                    <i class="glyphicon glyphicon-ok" style="color: green;"></i>
                </td>
            }
            else
            {
                <td class="text-center">
                    <i class="glyphicon glyphicon-remove" style="color: red;"></i>
                </td>
            }
            break;
        case TypeCode.DateTime:
            var dt = (DateTime)entity[item.Name];
            if (dt > DateTime.MinValue && dt.Year > 1900)
            {
                <td>@(((DateTime)entity[item.Name]).ToFullString(""))</td>
            }
            else
            {
                <td></td>
            }
            break;
        case TypeCode.Decimal:
        <td>@entity[item.Name]</td>
            break;
        case TypeCode.Single:
        case TypeCode.Double:
        <td>@entity[item.Name]</td>
            break;
        case TypeCode.Byte:
        case TypeCode.Int16:
        case TypeCode.Int32:
        case TypeCode.Int64:
        case TypeCode.UInt16:
        case TypeCode.UInt32:
        case TypeCode.UInt64:
            //特殊处理枚举
            if (item.Type.IsEnum)
            {
                <td class="text-center">@entity[item.Name]</td>
            }
            else
            {
                <td class="text-right">@Convert.ToInt64(entity[item.Name]).ToString("n0")</td>
            }
            break;
        case TypeCode.String:
        <td>@entity[item.Name]</td>
            break;
        default:
        <td>@entity[item.Name]</td>
            break;
    }
}